import { request } from "../easeserve";


// 获取时间戳
function getTime() {
  let timestamp = new Date().getTime();
  return timestamp;
}
/**
 * 登陆方法
 * 调用登录接口的速度比调用其他接口慢 , 因为登录过程调用了加密算法
 * @returns {phone} 手机号
 * @returns {password} 密码
 */
export const loginWithPhone = (phone, password, timestamp) => {
  return request({
    url: `/login/cellphone?phone=${phone}&password=${password}&timestamp=${timestamp}`,
    method: 'post',
  })
}
// 邮箱登陆
export const loginWithEmail = (data) => {
  return request({
    url: 'login',
    method: 'get',
    data: data
  })
}
// 二维码获取key
export const getQRCodeKey = () => {
  return request({
    url: `login/qr/key&timestamp=${getTime()}`,
    method: 'get',
  })
}
// 二维码的图片获取 需要时间戳
export const getQRCode = (unikey) => {
  return request({
    url: `login/qr/create?key=${unikey}&timestamp=${getTime()}`,
    method: 'get',
  })
}
// 二维码检测扫码状态接口
export const checkQRCode = (data) => {
  return request({
    url: 'login/qr/check',
    method: 'get',
    data: data
  })
}
// 刷新登录
export const checkRefresh = () => {
  return request({
    url: 'login/refresh',
    method: 'get'
  })
}
// 获取验证码
export const getCaptcha = (phone) => {
  return request({
    url: `captcha/sent?phone=${phone}`,
    method: 'get',
  })
}
// 发送验证码登录
export const sendCaptcha = (phone, captcha) => {
  return request({
    url: `/login/cellphone?phone=${phone}&captcha=${captcha}`,
    method: 'get',
  })
}
// 验证验证码
export const verifyCaptcha = (phone, captcha) => {
  return request({
    url: `captcha/verify?phone=${phone}&captcha=${captcha}`,
    method: 'get',
  })
}
// 注册(修改密码)
export const registerCellphone = (data) => {
  return request({
    url: 'register/cellphone',
    method: 'get',
    data: data
  })
}
// 初始化昵称
export const initProfile = (data) => {
  return request({
    url: 'activate/init/profile',
    method: 'get',
    data: data
  })
}
// 更换绑定手机 rebind
export const rebindPhone = (data) => {
  return request({
    url: 'rebind',
    method: 'get',
    data: data
  })
}
// 退出登录 logout
export const logout = () => {
  return request({
    url: `rebind`,
    method: 'get'
  })
}
// 登录状态
export const loginStatus = () => {
  return request({
    url: 'login/status',
    method: 'get'
  })
}

